package com.ljq.software_springboot.softwareprogram.mapper;

import com.ljq.software_springboot.softwareprogram.entity.UserGroup;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author author
 * @since 2024-12-28
 */
@Mapper
public interface UserGroupMapper extends BaseMapper<UserGroup> {
// 根据创建者 ID 获取分组及其成员信息
    @Select("SELECT g.id AS group_id, g.name AS group_name, gm.user_id, gm.id AS group_member_id " +
            "FROM usergroup g " +
            "JOIN group_member gm ON g.id = gm.group_id " +
            "WHERE g.creator_id = #{creatorId}")
    List<UserGroup> findGroupsByUsername(@Param("username") Integer creatorId);
}
